/**
 * Resource entity. Getters & setters.
 */
package com.xoomworks.rsfr.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * The persistent class for the resources database table.
 * @author andrea.ghisa
 *
 */
public class Resource extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    private Date availabilityEndDate;

    private Date availabilityStartDate;

    private Date createdOn;

    private BigDecimal hourlyRate;

    private Byte isPublished;

    private Date modifiedOn;

    private String privateName;

    private String publicName;

    // bi-directional many-to-one association to ResourceCompetency
    private List<ResourceCompetency> resourceCompetencies;

    // bi-directional many-to-one association to ResourceCompetency
    private List<ResourceHistory> resourceHistories;

    // uni-directional many-to-one association to User
    private User createdBy;

    // uni-directional many-to-one association to User
    private User modifiedBy;

    private Company company;

    /**
     * Constructor with no fields.
     */
    public Resource() {
    }

    /**
     * Constructor with specified parameters.
     * @param createdOn Date Represents the date when resource was created.
     * @param isPublished Byte Represents the status of resource (e.g 0-is not published, 1-is published)
     * @param publicName String Represents the public name of resource.
     * @param createdBy User Represents the user who created the resource.
     * @param company Company Represents the company from where is the user who created a resource.
     */
    public Resource(final Date createdOn, final Byte isPublished, final String publicName,
            final User createdBy, final Company company) {
        super();
        this.createdOn = createdOn;
        this.publicName = publicName;
        this.createdBy = createdBy;
        this.isPublished = isPublished;
        this.company = company;
    }

    /**
     * Constructor with specified parameters.
     * @param availabilityEndDate Date Represents the date until resource is available.
     * @param availabilityStartDate Date Represents the start date from when resource is available.
     * @param createdOn Date Represents the date when resource was created.
     * @param hourlyRate BigDecimal Represents the cost per hour.
     * @param isPublished Byte Represents the status of resource (e.g 0-is not published, 1-is published).
     * @param publicName String Represents the public name of resource.
     * @param createdBy createdBy User Represents the user who created the resource.
     * @param company Company Represents the company from where is the user who created a resource.
     */
    public Resource(final Date availabilityEndDate, final Date availabilityStartDate,
            final Date createdOn, final BigDecimal hourlyRate, final byte isPublished,
            final String publicName, final User createdBy, final Company company) {
        super();
        this.availabilityEndDate = availabilityEndDate;
        this.availabilityStartDate = availabilityStartDate;
        this.createdOn = createdOn;
        this.hourlyRate = hourlyRate;
        this.isPublished = isPublished;
        this.publicName = publicName;
        this.createdBy = createdBy;
        this.company = company;
    }



    /**
     * Constructor for initializing a resource with the data that a trusted.
     * company user can access.
     * @param id Represents resource id.
     * @param availabilityStartDate Date the start date from when resource is available.
     * @param availabilityEndDate Date Represents the date until resource is available.
     * @param hourlyRate BigDecimal Represents the cost per hour.
     * @param publicName String Represents the public name of resource.
     * @param privateName String Represents the private name of resource.
     * @param company Company Represents the company from where is the user who created a resource.
     */
    public Resource(final Long id, final Date availabilityStartDate,
            final Date availabilityEndDate, final BigDecimal hourlyRate, final String publicName,
            final String privateName, final Company company) {
        super();
        this.id = id;
        this.availabilityStartDate = availabilityStartDate;
        this.availabilityEndDate = availabilityEndDate;
        this.hourlyRate = hourlyRate;
        this.publicName = publicName;
        this.privateName = privateName;
        this.company = company;
    }


    /**
     * Constructor for initializing a resource with the data that a untrusted.
     * company user can access.
     * @param id Represents resource id.
     * @param availabilityStartDate Date the start date from when resource is available.
     * @param availabilityEndDate Date Represents the date until resource is available.
     * @param hourlyRate BigDecimal Represents the cost per hour.
     * @param publicName String Represents the public name of resource.
     */
    public Resource(final Long id, final Date availabilityStartDate,
            final Date availabilityEndDate, final BigDecimal hourlyRate, final String publicName) {
        super();
        this.id = id;
        this.availabilityStartDate = availabilityStartDate;
        this.availabilityEndDate = availabilityEndDate;
        this.hourlyRate = hourlyRate;
        this.publicName = publicName;
    }

    /**
     * Gets the date until resource is available.
     * @return availabilityEndDate Date Represents the date until resource is available.
     */
    public Date getAvailabilityEndDate() {
        return this.availabilityEndDate;
    }

    /**
     * Sets the date until resource is available.
     * @param availabilityEndDate Date Which is used to set the availabilityEndDate.
     */
    public void setAvailabilityEndDate(final Date availabilityEndDate) {
        this.availabilityEndDate = availabilityEndDate;
    }

    /**
     * Gets the start date from when resource is available.
     * @return availabilityStartDate Represents the start date from when resource is available.
     */
    public Date getAvailabilityStartDate() {
        return this.availabilityStartDate;
    }

    /**
     * Sets the availability start date.
     * @param availabilityStartDate Date Which is used to set the availabilityStartDate.
     */
    public void setAvailabilityStartDate(final Date availabilityStartDate) {
        this.availabilityStartDate = availabilityStartDate;
    }

    /**
     * Gets the date when resource was created.
     * @return createdOn Date Represents the date when resource was created.
     */
    public Date getCreatedOn() {
        return this.createdOn;
    }

    /**
     * Sets the date when resource was created.
     * @param createdOn Date Which is used to set the
     */
    public void setCreatedOn(final Date createdOn) {
        this.createdOn = createdOn;
    }

    /**
     * Gets the cost per hour.
     * @return hourlyRate  BigDecimal Represents the cost per hour.
     */
    public BigDecimal getHourlyRate() {
        return this.hourlyRate;
    }

    /**
     * Sets the cost per hour.
     * @param hourlyRate BigDecimal Which is used to set the
     */
    public void setHourlyRate(final BigDecimal hourlyRate) {
        this.hourlyRate = hourlyRate;
    }

    /**
     * Gets the status of resource.
     * @return isPublished Byte Represents the status of resource.
     */
    public Byte getIsPublished() {
        return this.isPublished;
    }

    /**
     * Sets the status of resource.
     * @param isPublished Byte Which is used to set the isPublished.
     */
    public void setIsPublished(final Byte isPublished) {
        this.isPublished = isPublished;
    }

    /**
     * Gets the date when the resource was modified.
     * @return modifiedOn Date Represents the date when the resource was modified.
     */
    public Date getModifiedOn() {
        return this.modifiedOn;
    }

    /**
     * Sets the date when the resource was modified.
     * @param modifiedOn  Date Which is used to set the modifiedOn
     */
    public void setModifiedOn(final Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    /**
     * Gets the private name of resource.
     * @return privateName String Represents the private name of resource.
     */
    public String getPrivateName() {
        return this.privateName;
    }

    /**
     * Sets the private name of resource.
     * @param privateName String Which is used to set the privateName.
     */
    public void setPrivateName(final String privateName) {
        this.privateName = privateName;
    }

    /**
     * Gets the public name of resource.
     * @return publicName String Represents the public name of resource.
     */
    public String getPublicName() {
        return this.publicName;
    }

    /**
     * Sets the public name of resource.
     * @param publicName String Which is used to set the publicName
     */
    public void setPublicName(final String publicName) {
        this.publicName = publicName;
    }


    /**
     * Gets the user who created the resource.
     * @return createdBy User the user who created the resource.
     */
    public User getCreatedBy() {
        return this.createdBy;
    }

    /**
     * Sets the user who created the resource.
     * @param createdBy User Which is used to set the createdBy
     */
    public void setCreatedBy(final User createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * Gets  the user who created the resource.
     * @return  User modifiedBy Represents the user who created the resource.
     */
    public User getModifiedBy() {
        return this.modifiedBy;
    }

    /**
     * Sets the user who created the resource.
     * @param modifiedBy User Which is used to set the modifiedBy
     */
    public void setModifiedBy(final User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    /**
     * Gets the company from where is the user who created a resource.
     * @return company Represents the company from where is the user who created a resource.
     */
    public Company getCompany() {
        return company;
    }

    /**
     * Sets the company from where is the user who created a resource.
     * @param company Company Which is used to set the company.
     */
    public void setCompany(final Company company) {
        this.company = company;
    }


    /**
     * Gets resource competencies.
     * @return resourceCompetencies List<ResourceCompetency> Represents resource competencies.
     */
    public List<ResourceCompetency> getResourceCompetencies() {
        return resourceCompetencies;
    }

    /**
     * Sets resource competencies.
     * @param resourceCompetencies List<ResourceCompetency> Which is used to set the resourceCompetencies
     */
    public void setResourceCompetencies(
            final List<ResourceCompetency> resourceCompetencies) {
        this.resourceCompetencies = resourceCompetencies;
    }

    /**Gets the resource history.
     * @return resourceHistories List<ResourceHistory> Represents the resource history.
     */
    public List<ResourceHistory> getResourceHistories() {
        return resourceHistories;
    }

    /**
     * Sets the resource history.
     * @param resourceHistories Which is used to set the resourceHistories
     */
    public void setResourceHistories(final List<ResourceHistory> resourceHistories) {
        this.resourceHistories = resourceHistories;
    }

    @Override
    public String toString() {
        return "Resource [id= "+ id + " availabilityEndDate=" + availabilityEndDate + ", availabilityStartDate="
                + availabilityStartDate + ", createdOn=" + createdOn + ", hourlyRate=" + hourlyRate
                + ", isPublished=" + isPublished + ", modifiedOn=" + modifiedOn + ", privateName="
                + privateName + ", publicName=" + publicName + ", resourceCompetencies="
                + resourceCompetencies + ", resourceHistories=" + resourceHistories
                + ", createdBy=" + createdBy + ", modifiedBy=" + modifiedBy + ", company="
                + company + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = (prime
                * result)
                + ((availabilityEndDate == null) ? 0 : availabilityEndDate
                        .hashCode());
        result = (prime
                * result)
                + ((availabilityStartDate == null) ? 0 : availabilityStartDate
                        .hashCode());
        result = (prime * result)
                + ((hourlyRate == null) ? 0 : hourlyRate.hashCode());
        result = (prime * result)
                + ((isPublished == null) ? 0 : isPublished.hashCode());
        result = (prime * result)
                + ((privateName == null) ? 0 : privateName.hashCode());
        result = (prime * result)
                + ((publicName == null) ? 0 : publicName.hashCode());
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Resource other = (Resource) obj;
        if (availabilityEndDate == null) {
            if (other.availabilityEndDate != null) {
                return false;
            }
        } else if (!availabilityEndDate.equals(other.availabilityEndDate)) {
            return false;
        }
        if (availabilityStartDate == null) {
            if (other.availabilityStartDate != null) {
                return false;
            }
        } else if (!availabilityStartDate.equals(other.availabilityStartDate)) {
            return false;
        }
        if (hourlyRate == null) {
            if (other.hourlyRate != null) {
                return false;
            }
        } else if (!hourlyRate.equals(other.hourlyRate)) {
            return false;
        }
        if (isPublished == null) {
            if (other.isPublished != null) {
                return false;
            }
        } else if (!isPublished.equals(other.isPublished)) {
            return false;
        }
        if (privateName == null) {
            if (other.privateName != null) {
                return false;
            }
        } else if (!privateName.equals(other.privateName)) {
            return false;
        }
        if (publicName == null) {
            if (other.publicName != null) {
                return false;
            }
        } else if (!publicName.equals(other.publicName)) {
            return false;
        }
        return true;
    }

}
